package com.wteam.controller.common;

import com.wteam.framework.common.enums.ResultCode;
import com.wteam.framework.common.enums.ResultUtil;
import com.wteam.framework.common.vo.ResultMessage;
import com.wteam.framework.modules.community.entity.SdModelMark;
import com.wteam.framework.modules.community.mapper.SdModelMarkMapper;
import com.wteam.framework.modules.community.service.SdModelMarkService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author doncic
 * @date 2023/7/14 18:56
 */
@Slf4j
@Tag(name = "模型书签接口管理")
@RestController
@RequestMapping("/api/modelMark")
public class ModelMarkController {

    @Autowired
    private SdModelMarkService sdModelMarkService;


    /**
     * 查询所有的模型书签，然后分页展示
     *
     * @return
     */
    @Operation(summary = "展示所有模型书签")
    @GetMapping("/getAllModelMark")
    public ResultMessage getAllModelMark() {
        return sdModelMarkService.getAllModelMark();
    }


    /**
     * 增加模型书签
     *
     * @param sdModelMark
     * @return
     */

    @Operation(summary = "用户增加书签")
    @PostMapping("/addModelMark")
    public ResultMessage addModelMark(@RequestBody SdModelMark sdModelMark) {

        return sdModelMarkService.addModelMark(sdModelMark)
                ? ResultUtil.success()
                : ResultUtil.error(ResultCode.MODEL_MARK_ADD_ERROR);

    }

    /**
     * 根据id删除书签
     *
     * @param id
     * @return
     */

    @Operation(summary = "用户删除书签")
    @DeleteMapping("/{id}")
    public ResultMessage deleteModelMark(@PathVariable("id") Long id) {
        return sdModelMarkService.deleteModelMark(id);
    }

    /**
     * 根据id更改书签
     *
     * @param id
     * @param sdModelMark
     * @return
     */

    @Operation(summary = "更改书签")
    @PutMapping("/{id}")
    public ResultMessage updateModelMark(@PathVariable("id") Long id, @RequestBody SdModelMark sdModelMark) {
        sdModelMark.setId(id);
        return sdModelMarkService.updateById(sdModelMark)
                ? ResultUtil.success()
                : ResultUtil.error(90008, "更改书签失败！");
    }

    /**
     * 根据书签查找模型
     * 这里是指的所有模型，后面还有在某个作者下根据书签查找
     * 模型社区首页也是如此展示，具体要展示的前端获取到模型属性之后可以自行选择
     *
     * @param markName
     * @return
     */
    @Operation(summary = "根据书签查找模型")
    @GetMapping("/getModelByMark")
    public ResultMessage getModelByMark(@RequestParam("markName") String markName) {
        return sdModelMarkService.findModelByMark(markName);
    }
}
